//decl sockaddr socket bind listen accept 
#include <sys/socket.h>
#include <sys/types.h>

//decl sockaddr_un
#include <linux/un.h>

//decl strcpy strlen
#include <string.h>

#define MAXBACKLOG 20
#define MAXBUF 1024

typedef struct sockaddr SockAddr;
typedef struct sockaddr_un SockAddrUn;

static int sfd;
static SockAddrUn s_un_addr;
static int conted_fd;
static char const wl[] = "Welcome!\n";
static char const sun_path[] = "/tmp/test.socket";
static char buf[MAXBUF];
static int len;

static void str2upper(char s[], int len) {
	int i;
	for(i=0; i<len; i++) {
		s[i] = toupper(s[i]);
	}
}

int main(void)
{
	s_un_addr.sun_family = AF_UNIX;
	strcpy(s_un_addr.sun_path, sun_path);
	sfd = socket(AF_UNIX, SOCK_STREAM, 0);
	unlink(sun_path);
	bind(sfd, (SockAddr*)&s_un_addr, sizeof(s_un_addr));
	listen(sfd, MAXBACKLOG);
	conted_fd = accept(sfd, NULL, NULL);
	write(conted_fd, wl, strlen(wl));					
	len = read(conted_fd, buf, MAXBUF);
	str2upper(buf, len);
	write(conted_fd, buf, len);
	close(conted_fd);
	return 0;
}
